package com.qf.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @ClassName MyAsepcet
 * @Description TODO
 * @Author 86181
 * @Date 2022/9/13 15:26
 * @Version 1.0
 **/
@Aspect
@Component
public class MyAsepcet {
    private static  final Logger logger=  LoggerFactory.getLogger(MyAsepcet.class);
    @Pointcut(value = "execution(* *.*.*.impl.*.*(..))")
    public void pt1(){

    }
    @Around("pt1()")
    public Object around(ProceedingJoinPoint proceedingJoinPoint){
        logger.debug("开始记录日志:"+new Date());
        //获取执行方法
        MethodSignature signature = (MethodSignature) proceedingJoinPoint.getSignature();
        logger.debug("执行方法为:"+signature.getMethod());
        Object proceed=null;
        try {
            proceed = proceedingJoinPoint.proceed();
            logger.debug("执行的方法为"+signature.getMethod()+"=执行完成");
        } catch (Throwable throwable) {
            throwable.printStackTrace();
            logger.error("执行的方法为："+signature.getMethod()+"出现异常：{}"+throwable.getMessage());
        }finally {
            logger.debug("执行时间为:"+new Date());
        }
        return proceed;
    }
}
